<?php
require('cacher2.class.php');
//очистить полностью память и файлы
$clear=true;
$cacher=new DiskCacher($clear);

//insert records 
$records=1000*1000;
$t1=mktime();
echo("\n".$records.'`s inserting'."\n");
for($i=1;$i<=$records;$i++){
if($i%1000==0)echo $i/1000,' ';
	$cacher->set($i,'qwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwertyqwerty');
}
$t2=mktime();
echo("\n".$records.'`s inserted by  '.round(($t2-$t1),3).' seconds, '.round(($records/($t2-$t1)),2).' per second'."\n");


//insert records 
$records=1000*1000;
$t1=mktime();
echo("\n".$records.'`s inserting'."\n");
for($i=1;$i<=$records;$i++){
if($i%1000==0)echo $i/1000,' ';
	$cacher->get($i);
}
$t2=mktime();
echo("\n".$records.'`s selected by  '.round(($t2-$t1),3).' seconds, '.round(($records/($t2-$t1)),2).' per second'."\n");

/*
$t1=mktime();
for($i=1;$i<100000;$i++){
if($i%1000==0)echo $i/1000,' ';
	$cacher->get($i);
}
$t2=mktime();
var_dump('get',($t2-$t1));
*/

for($i=1;$i<100;$i++){
	//echo $i;
	//$cacher->set($i*100,'aaa');
}
//echo 'defragment';
//$cacher->lazyDefragment();
//var_dump('value',$cacher->get(1),$cacher->get(2));
//var_dump('offsets',shm_get_var($cacher->shmIndex,1),
	//shm_get_var($cacher->shmIndex,2));


?>
